package demo150;

public class lengthOfLastWord {
    public int lengthOfLastWord2(String s) {
        String[] split = s.split(" ");
        return split[split.length-1].length();
    }
    public int lengthOfLastWord(String s) {
        int ret = 0;
        for(int i = s.length()-1;i >= 0;i--) {
            if(s.charAt(i) != ' '){
                while(i >= 0 && s.charAt(i) != ' '){
                    ret++;
                    i--;
                }
                break;
            }
        }
        return ret;
    }
}
